package com.pure.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.pure.dao.BusinessMapper;
import com.pure.dao.DevelopMapper;
import com.pure.dao.JobbusinessinfoMapper;
import com.pure.dao.UserMapper;
import com.pure.dao.UserinfoMapper;
import com.pure.dao.UserjobMapper;
import com.pure.db.Business;
import com.pure.db.BusinessExample.Criteria;
import com.pure.db.Develop;
import com.pure.db.Jobbusinessinfo;
import com.pure.db.JobbusinessinfoExample;
import com.pure.db.User;
import com.pure.db.Userinfo;
import com.pure.db.UserinfoExample;
import com.pure.db.Userjob;
import com.pure.db.UserjobExample;
import com.pure.service.UserService;

import oracle.net.aso.e;

@Service
public class UserServiceImpl  extends CommonServiceImpl implements UserService {

	
   
	@Resource
	private UserMapper userMapper;
	
	@Resource
	private BusinessMapper businessMapper;
	@Resource
	private JobbusinessinfoMapper jobbusinessinfoMapper;
	@Resource
	private UserinfoMapper userinfoMapper;
	@Resource
	private DevelopMapper developMapper;
	@Resource
	private UserjobMapper userjobMapper;
	
    @Override
	public User getUserByLoginName(String username, String password) {
         User user=userMapper.getUserByName(username);
	     if (user!=null) {
			 if (user.getPassword().equals(password)) {//验证成功
				return user;
			 }
		 }
	     return user;
    }

	@Override
	public Integer addUser(User user) {
		return userMapper.insertSelective(user);
	}

	@Override
	public Business getBusinessByLoginName(String username, String password) {
		Business business=businessMapper.getBusinessByLoginName(username);
		     if (business!=null) {
				 if (business.getPassword().equals(password)) {//验证成功
					return business;
				 }
			 }
		     return business;
	}

	@Override
	public Integer updateUser(User user) {
		return userMapper.updateByPrimaryKeySelective(user);
	}

	@Override
	public Integer addBussiness(Business business) {
		return businessMapper.insertSelective(business);
	}

	@Override
	public Integer updateBussiness(Business business) {
		return businessMapper.updateByPrimaryKeySelective(business);
	}

	@Override
	public Jobbusinessinfo selectBussinessInfoById(Integer id) {
		return jobbusinessinfoMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Jobbusinessinfo> selectBussinessInfo(Integer id) {
		JobbusinessinfoExample example = new JobbusinessinfoExample();
		example.createCriteria().andBusinessidEqualTo(id);
		
		return jobbusinessinfoMapper.selectByExample(example);
	}

	@Override
	public Integer updateBussinessInfo(Jobbusinessinfo jobbusinessinfo) {
		return jobbusinessinfoMapper.updateByPrimaryKeySelective(jobbusinessinfo);
	}

	@Override
	public Integer addBussinessInfo(Jobbusinessinfo jobbusinessinfo) {
		return jobbusinessinfoMapper.insertSelective(jobbusinessinfo);
	}

	@Override
	public Integer deleteBussinessInfo(Integer id) {
		UserjobExample ex = new UserjobExample();
		ex.createCriteria().andJobidEqualTo(id);
		return jobbusinessinfoMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Integer addUserInfo(Userinfo userinfo) {
		return userinfoMapper.insertSelective(userinfo);
	}

	@Override
	public Integer updateUserInfo(Userinfo userinfo) {
		return userinfoMapper.updateByPrimaryKeySelective(userinfo);
	}

	@Override
	public List<Userinfo> selectUserinfo(Integer id) {
		UserinfoExample example = new UserinfoExample();
		example.createCriteria().andUseridEqualTo(id);
		
		return userinfoMapper.selectByExample(example);
	}

	@Override
	public Userinfo selectUserinfoById(Integer id) {
		return userinfoMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Jobbusinessinfo> getAllBussinessInfo(String type) {
		JobbusinessinfoExample example = new JobbusinessinfoExample();
		example.createCriteria().andTypeLike(type);
		return jobbusinessinfoMapper.selectByExample(example);
	}

	@Override
	public Develop getDevelopByLoginName(String username, String password) {
		Develop develop=developMapper.getDevelopByLoginName(username);
	     if (develop!=null) {
			 if (develop.getPassword().equals(password)) {//验证成功
				return develop;
			 }
		 }
	     return develop;
	}

	@Override
	public Integer applyBusiness(Userjob userjob) {
		// TODO Auto-generated method stub
		return userjobMapper.insertSelective(userjob);
	}

	@Override
	public Integer applyStatusBusiness(Userjob userjob) {
		// TODO Auto-generated method stub
		return userjobMapper.updateByPrimaryKeySelective(userjob);
	}

	@Override
	public Userjob getUserjobById(Integer id) {
		// TODO Auto-generated method stub
		return userjobMapper.selectByPrimaryKey(id);
	}

	@Override
	public User getUserById(Integer id) {
		// TODO Auto-generated method stub
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	public Business getBussinessById(Integer id) {
		// TODO Auto-generated method stub
		return businessMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Map<String, Object>> getApplyUserinfo(Integer jobbusinessid, Integer status) {
		Map<String, Object> map = new HashMap<>();
		map.put("jobid", jobbusinessid);
		map.put("status", status);
		List<Map<String, Object>> userinfos = userinfoMapper.getApplyUserinfo(map);
		return userinfos;
	}

	@Override
	public List<Jobbusinessinfo> getAllBussinessInfo1() {
		JobbusinessinfoExample example = new JobbusinessinfoExample();
		example.createCriteria();
		return jobbusinessinfoMapper.selectByExample(example);
	}

	@Override
	public boolean checkUse(Integer id) {
		Userjob user = userjobMapper.checkUse(id);
		boolean flag = false;
		if (user != null) {
			flag = true;
		}
		return flag;
	}

	@Override
	public Map<String, Object> selectUserinfoByIdAndStatus(Integer id) {
		return userinfoMapper.selectUserinfoByIdAndStatus(id);
	}

	@Override
	public Integer deleteUserInfo(Integer id) {
		UserjobExample ex = new UserjobExample();
		ex.createCriteria().andUserinfoidEqualTo(id);
		return userinfoMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Business getBussinessByjobid(Integer jobid) {
		// TODO Auto-generated method stub
		Jobbusinessinfo jobbusinessinfo = jobbusinessinfoMapper.selectByPrimaryKey(jobid);
		return businessMapper.selectByPrimaryKey(jobbusinessinfo.getBusinessid());
	}

	@Override
	public List<Jobbusinessinfo> getAllBussinessInfo1(Date starttime, Date endtime) {
		JobbusinessinfoExample example = new JobbusinessinfoExample();
		example.createCriteria().andStarttimeBetween(starttime, endtime).andEndtimeBetween(starttime, endtime);
		return jobbusinessinfoMapper.selectByExample(example);
	}

}
